@{    
    Layout = "~/Views/Shared/_LayoutJtable.cshtml";  
}
@{ViewBag.Title = "Gestione Datos";}


<div class="filtering"><form>
<label>Indroduzca texto para filtrar: <input type="text" name="filter" id="filter" /></label>
<button type="submit" id="LoadRecordsButton" class="button medium green">Filtrar Datos</button>
 @Html.ActionLink("Crear Nuevo Usuario", "DataForm", null, new { @class = "button medium green" })
</form></div>
<div id="MyTableContainer"></div>
<script type="text/javascript">
     $(document).ready(function () {
     $('#MyTableContainer').jtable({
         title: 'DUA_Usuario',
         paging: true,
         pageSize: 20,
         sorting: true,
         defaultSorting: 'Id ASC',
         actions: {
             listAction: '@Url.Action("JSONPagedListByFilter")',
             deleteAction: '@Url.Action("JSONDelete")',
             updateAction: '@Url.Action("JSONUpdate")',
             createAction: '@Url.Action("JSONCreate")'
         },
         fields:
         {
          Id: {
                 key: true,
                 create: false,
                 edit: false,
                 list: false
             }
             ,
             Nombre: {
                 title:'Nombre',
                 create: true,
                 edit: true,
                 list: true,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             Contrasena: {
                 title:'Contrasena',
                 create: true,
                 edit: true,
                 list: true,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             PreguntaSeguridad: {
                 title:'PreguntaSeguridad',
                 create: true,
                 edit: true,
                 list: true,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             RespuestaSeguridad: {
                 title:'RespuestaSeguridad',
                 create: true,
                 edit: true,
                 list: true,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             Bloqueado: {
                 title:'Bloqueado',
                 create: true,
                 edit: true,
                 list: true,
                 type: 'checkbox',
                 values:{'false':'Desactivado','true':'Activado'},
                 sorting: false
             }
             ,
             PersonaId_FK:{
                 title : 'DUA_Persona',
                 create : true,
                 edit : false,
                 list : true,
                 options : '../../Persona/JSONGetElementsForDropDownList'
             }
             ,
             RolId_FK:{
                 title : 'DUA_Rol',
                 create : true,
                 edit : true,
                 list : true,
                 options : '@Url.Action("../Rol/JSONGetElementsForDropDownList")'
             },

             Edit:
             {
                  title: 'Acciones',
                  width: '10%',
                  sorting: false,
                  edit: false,
                  create: false,
                  display: function (tempData) {
                      var $enlace = $('<a class="item-link" href="Redirector?ide=' +tempData.record.Id + '">Editar</a>');
                        return $enlace;
                    }
                }

},
formCreated: function (event, data) {data.form.validationEngine();},
formSubmitting: function (event, data) {return data.form.validationEngine('validate');},
formClosed: function (event, data) { data.form.validationEngine('hide'); data.form.validationEngine('detach'); }
});
$('#LoadRecordsButton').click(function (e) {e.preventDefault();$('#MyTableContainer').jtable('load', {filter: $('#filter').val()});});
$('#LoadRecordsButton').click();
});
</script>

